﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：李刚 
    //
    // 文件名：DistributeRelationList.cs
    // 文件功能描述：可配送采购产品列表
    // 创建标识：李刚2009-04-03
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.BidProdManage
{
    public partial class DistributeRelationList : BasePage
    {
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        public DistributeRelationList()
        {
            this.ModuleNo = Module.配送关系管理.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //绑定所有项目
                IList<ProcurementProject> projectList = ipb.GetAllProcurementProject();
                ddlProject.DataSource = projectList;
                ddlProject.DataTextField = "ProjectName";
                ddlProject.DataValueField = "ProjectID";
                ddlProject.DataBind();
                ListItem item = new ListItem();
                item.Text = Constants.ALL_ITEM_TEXT;
                item.Value = Constants.ALL_ITEM_VALUE;
                ddlProject.Items.Insert(0, item);
                setBind();
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            setBind();
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            setBind();
        }

        private void setBind()
        {
            //获取查询条件
            Model.Query.ProcureCatalog procureCatalog = new HZ.DrugTrade.Model.Query.ProcureCatalog();
            procureCatalog.CompanyName_SC = txtProduceCompany_SC.Text.Trim();
            procureCatalog.GoodsName = txtGoodsName.Text.Trim();
            procureCatalog.Material = txtMaterial.Text.Trim();
            procureCatalog.Outlookc = txtOutLook.Text.Trim();
            procureCatalog.ProjectID = ddlProject.SelectedItem.Value;
            procureCatalog.CompanyName_TB = txtCompany_TB.Text;
            procureCatalog.SortFields = " GoodsName asc";
            procureCatalog.Unit = txtUnit.Text.Trim();

            if (!string.IsNullOrEmpty(txtProcureStartTime.Text.Trim()))
            {
                procureCatalog.ProcureStartTime = Convert.ToDateTime(txtProcureStartTime.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtProcureEndTime.Text.Trim()))
            {
                procureCatalog.ProcureEndTime = Convert.ToDateTime(txtProcureEndTime.Text.Trim());
            }

            //调用方法，执行查询，分页显示产品信息
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
            try
            {

                IList<Model.View.ProcureCatalog> procureCatalogList = ipb.GetProcureCatalogByWhere(procureCatalog, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
                AspNetPager1.RecordCount = totalCount;
                gvwProduceCatalog.DataSource = procureCatalogList;
                gvwProduceCatalog.DataBind();
            }
            catch (Exception ex)
            {
                PageError(ex.Message, "");
            }
        }

        /// <summary>
        /// 简单查询与高级查询之间的转换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnSwitch_Click(object sender, EventArgs e)
        {
            if (lbnSwitch.CommandArgument == "simple")
            {
                ltlAdvance.Text = "";
                lbnSwitch.CommandArgument = "advance";
                lbnSwitch.Text = "简单查询";
            }
            else
            {
                ltlAdvance.Text = "<tbody id='advance' style='display:none'>";
                lbnSwitch.CommandArgument = "simple";
                lbnSwitch.Text = "高级查询";

                //清空数据
                txtCompany_TB.Text = "";
                txtMaterial.Text = "";
                txtGoodsName.Text = "";
                txtProcureEndTime.Text = "";
                txtProcureStartTime.Text = "";
                txtProduceCompany_SC.Text = "";
                txtUnit.Text = "";
                ddlProject.SelectedIndex = -1;
            }
        }
    }
}
